<?php

function __autoload($class) {
    require str_replace("\\", '/', $class) . '.php';
}

$themeDir = __DIR__ . '/DebugComponent/Themes/Default/';
//echo file_get_contents('http://www.jobs.cz/');
$d = \DebugComponent\Builder::build(array(
    new \DebugComponent\Plugin\Message(),
    new \DebugComponent\Plugin\Time(),
    new \DebugComponent\Plugin\Memory(),
    new \DebugComponent\Plugin\File(),
    new \DebugComponent\Plugin\Database(),
    new \DebugComponent\Plugin\Dump(),
    $settings = new \DebugComponent\Plugin\Settings(),
    new \DebugComponent\Plugin\PHPInfo(),
    $version = new \DebugComponent\Plugin\Version(array('application'=>'1.0.0', 'framework'=>'2.0.0')),
    new \DebugComponent\Plugin\Log(
            new \DebugComponent\Storage\File('/tmp/global.log'),
            null,
            new \DebugComponent\Formatter\Mask('{year}-{month}-{day} {hour}:{minute}:{second} [{type}] - {message}')),
    new \DebugComponent\Plugin\Log(
            new \DebugComponent\Storage\File('/tmp/error.log'),
            new \DebugComponent\Filter\Type(array('\DebugComponent\Message\Error')),
            new \DebugComponent\Formatter\Mask('{year}-{month}-{day} {hour}:{minute}:{second} {message->getFilename}:{message->getLine} {message}')),
), $themeDir);

$settings->add('test', '11', 'global');
$settings->add('key', '22', 'section 1');
$settings->add('test2', array(1,2,3), 'global');

$version->setMainVersion('1.0.0');

\set_error_handler(function($errno, $errstr, $errfile, $errline) use ($d) {
    $d->dispatch(new \DebugComponent\Message\Error($errstr . ' ' . $errfile . ':' . $errline));
});

$d->dispatch(new \DebugComponent\Message\Info('test'));
$d->dispatch(new \DebugComponent\Message\Warning('test'));
$d->dispatch(new \DebugComponent\Message\Time('test time', 10));
$d->dispatch(new \DebugComponent\Message\Memory('test memory', 10));
$d->dispatch(new \DebugComponent\Message\Memory('test memory', 20));
$d->dispatch(new \DebugComponent\Message\Memory('test memory2', 300.5));
$d->dispatch(new \DebugComponent\Message\Time('test abc', 20));
for ($i = 0; $i < 5; $i++) {
$d->dispatch(new \DebugComponent\Message\Time('test time2', 10));
}

$d->dispatch(new \DebugComponent\Message\Database('testing database', 'pgsql://test:test@myhost.com'));
$d->dispatch(new \DebugComponent\Message\Database('testing database2', 'pgsql://test:test@myhost2.com'));
$d->dispatch(new \DebugComponent\Message\Query('SELECT * FROM abc', 10, 'pgsql://test:test@myhost.com'));
$d->dispatch(new \DebugComponent\Message\Query('SELECT * FROM def', 10, 'pgsql://test:test@myhost.com'));
$d->dispatch(new \DebugComponent\Message\Query('SELECT * FROM abc', 10, 'pgsql://test:test@myhost.com'));
$d->dispatch(new \DebugComponent\Message\Query('SELECT * FROM abc', 200, 'pgsql://test:test@myhost2.com'));
$d->dispatch(new \DebugComponent\Message\File('Testing file', '/tmp/a.txt'));
$c = $aa;
$e = $bb;
$f = $bb;
$d->dispatch(new \DebugComponent\Message\Memory('test memory', 20));

class Test {
    public $a = 'abc';
}
$qqq = new Test();
$abc = array(1,2,3=>array('a','b','c'=>array(2,2,2), 'd' => $qqq));
$d->dispatch(new \DebugComponent\Message\Dump('test variable', $abc));
$d->dispatch(new \DebugComponent\Message\Dump('test variable', $abc));

echo $d->render();